// DlgScrollable.cpp : implementation file
//

#include "stdafx.h"
#include "../Frame/GYWalkAidApp.h"
#include "ScrollPage.h"
#include "../Common/CommonFun.h"
#include "../Common/LinkEdit.h"
#include "../Common/GYDataSet.h"
#include "../Common/LinkComboBox.h"

#include "BCMiniMentalPage.h"
#include "BCTinettiBalPage.h"
#include "BCBergScorePage.h"
#include "BCBrunnstromPage.h"
#include "BCDoctorWritePage.h"
#include "BCFuglMeyerBalPage.h"
#include "BCFuglMeyerLowPage.h"
#include "BCFuglMeyerUpPage.h"
#include "BCHoldenWalkPage.h"
#include "BCReviseAshworthPage.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CScrollPage dialog


CScrollPage::CScrollPage(UINT nIDTemplate, CWnd* pParent)
	: CDialog(nIDTemplate, pParent)
{
	m_nPangeIndex			= -1;
}


/////////////////////////////////////////////////////////////////////////////
// CScrollPage message handlers

BOOL CScrollPage::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// save the original size
	// initial scroll position
	GetWindowRect(&m_rect);

	m_nScrollPos = 0; 
	
	return FALSE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CScrollPage::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	int nDelta;
	int nMaxPos = m_rect.Height() - m_nCurHeight;
	
	switch (nSBCode)
	{
	case SB_LINEDOWN:
		if (m_nScrollPos >= nMaxPos)
			return;
		
		nDelta = min(max(nMaxPos/20,5),nMaxPos-m_nScrollPos);
		break;
		
	case SB_LINEUP:
		if (m_nScrollPos <= 0)
			return;
		nDelta = -min(max(nMaxPos/20,5),m_nScrollPos);
		break;

	case SB_PAGEDOWN:
		if (m_nScrollPos >= nMaxPos)
			return;
		nDelta = min(max(nMaxPos/10,5),nMaxPos-m_nScrollPos);
		break;
		
	case SB_PAGEUP:
		if (m_nScrollPos <= 0)
			return;
		nDelta = -min(max(nMaxPos/10,5),m_nScrollPos);
		break;
		
	case SB_THUMBTRACK:
	case SB_THUMBPOSITION:
		nDelta = (int)nPos - m_nScrollPos;
		break;
		
	default:
		return;
	}
	m_nScrollPos += nDelta;
	SetScrollPos(SB_VERT,m_nScrollPos,TRUE);
	ScrollWindow(0,-nDelta);
	
	CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
}

void CScrollPage::OnSize(UINT nType, int cx, int cy) 
{
	CDialog::OnSize(nType, cx, cy);

	// TODO: Add your message handler code here.
	m_nCurHeight = cy;
	int nScrollMax;
	if (cy < m_rect.Height())
		nScrollMax = m_rect.Height();
	else
		nScrollMax = 0;
	
	SCROLLINFO si;
	si.cbSize = sizeof(SCROLLINFO);
	si.fMask = SIF_ALL; // SIF_ALL = SIF_PAGE | SIF_RANGE | SIF_POS;
	si.nMin = 0;
	si.nMax = nScrollMax;
	si.nPage = cy;
	si.nPos = 0;
	SetScrollInfo(SB_VERT, &si, TRUE); 

}

BOOL CScrollPage::Create(UINT nIDTemplate, CWnd* pParentWnd, int nIndex)
{
	m_nPangeIndex = nIndex;

	return CDialog::Create(nIDTemplate, pParentWnd);
}

BOOL CScrollPage::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt) 
{
	// TODO: Add your message handler code here and/or call default
	int nMaxPos = m_rect.Height() - m_nCurHeight;
	
	if (zDelta<0)
	{
		if (m_nScrollPos < nMaxPos)
		{
			zDelta = min(max(nMaxPos/20,5), nMaxPos-m_nScrollPos);
			
			m_nScrollPos += zDelta;
			SetScrollPos(SB_VERT,m_nScrollPos,TRUE);
			ScrollWindow(0,-zDelta);
		}
	}
	else
	{
		if (m_nScrollPos > 0)
		{
			zDelta = -min(max(nMaxPos/20,5),m_nScrollPos);
			
			m_nScrollPos += zDelta;
			SetScrollPos(SB_VERT,m_nScrollPos,TRUE);
			ScrollWindow(0,-zDelta);
		}
	}
	
	return CDialog::OnMouseWheel(nFlags, zDelta, pt);
}

BOOL CScrollPage::PageClearData(INPUT_FIELD_INFO* ppCtrlArrays[], int nColCtrlCount, CWnd* pDateLabelArray[], CWnd* pDiagSNArray[], int nDateCtrlCount)
{
	for(int i = 0; i < nDateCtrlCount; i++)
	{
		for(int j = 0; j < nColCtrlCount; j++)
		{
			if(ppCtrlArrays[i][j].dwCtrlType == IBT_ComboBox)
			{
				CLinkComboBox* pCombo = (CLinkComboBox*)ppCtrlArrays[i][j].pLinkCtrl;
				if(pCombo)
					pCombo->SetCurSel(0);
			}
			else if(ppCtrlArrays[i][j].dwCtrlType == IBT_EditBox)
			{
				CLinkEdit* pEdit = (CLinkEdit*)ppCtrlArrays[i][j].pLinkCtrl;
				if(pEdit)
					pEdit->SetWindowText(_T(""));
			}
			else
			{
				ASSERT(FALSE);
			}
		}
		
		if(i == (nDateCtrlCount - 1))
		{
			CTime curTime = CTime::GetCurrentTime();
			CString strCheckDate;
			strCheckDate.Format(_T("%4d-%02d-%02d"), curTime.GetYear(), curTime.GetMonth(), curTime.GetDay());

			pDateLabelArray[i]->SetWindowText(strCheckDate);
		}
		else
		{
			pDateLabelArray[i]->SetWindowText(GetResString(IDS_PAT_NONE_DATE));
		}

		pDiagSNArray[i]->SetWindowText(_T(""));
	}
	
	return TRUE;
}

BOOL CScrollPage::PageScoreFieldsCheck(LPVOID pParam, int nLowLimit, int HighLimit, INPUT_FIELD_INFO* pCtrlArrays, int nColCtrlCount)
{
	if(pParam)
	{
		INPUT_FIELD_INFO* pFieldInfo = (INPUT_FIELD_INFO*)pParam;

		if(pFieldInfo->pLinkCtrl && pFieldInfo->dwCtrlType == IBT_ComboBox)
		{
			int nTotal = 0;
			BOOL bAllBlank = TRUE;

			for(int i = 0; i < nColCtrlCount - 1; i++)
			{
				CLinkComboBox* pCombo = (CLinkComboBox*)pCtrlArrays[i].pLinkCtrl;
				if(pCombo)
				{
					CString strText = pCombo->GetControlData();
					
					int nSel = _ttoi(strText);
					if(nSel > 0)
					{
						CString strScore;
						pCombo->GetLBText(nSel, strScore);
						
						int nScore = _ttoi(strScore);
						if(nScore < 9)			//  !!!!!!!!!!!!!!! 9 is unknown, for Mini Mental Scale
							nTotal += nScore;
						
						bAllBlank = FALSE;
					}
				}
			}

			if(nColCtrlCount > 1)
			{
				CLinkEdit* pTotalEdit = (CLinkEdit*)pCtrlArrays[nColCtrlCount - 1].pLinkCtrl;
				if(bAllBlank)
				{
					if(pTotalEdit)
						pTotalEdit->SetWindowText(_T(""));
				}
				else
				{
					CString strTotal;
					strTotal.Format(_T("%d"), nTotal);
					
					if(pTotalEdit)
						pTotalEdit->SetWindowText(strTotal);
				}
			}
		}

		if(pFieldInfo->pLinkCtrl && pFieldInfo->dwCtrlType == IBT_EditBox)
		{
			CLinkEdit* pEdit = (CLinkEdit*)pFieldInfo->pLinkCtrl;
			
			CString strText = pEdit->GetControlData();
			int nScore = _ttoi(strText);
			
			if(nScore < nLowLimit || nScore > HighLimit)
			{
				GYMsgBox(IDS_GBL_INVALID_DATA, MB_OK|MB_ICONINFORMATION);
				return FALSE;
			}
			
			int nTotal = 0;
			BOOL bAllBlank = TRUE;
			for(int i = 0; i < nColCtrlCount - 1; i++)
			{
				CLinkEdit* pEdit = (CLinkEdit*)pCtrlArrays[i].pLinkCtrl;
				if(pEdit)
				{
					CString strText = pEdit->GetControlData();
					
					int nScore = _ttoi(strText);

					if(nScore < 9)			//  !!!!!!!!!!!!!!! 9 is unknown, for Mini Mental Scale
						nTotal += nScore;
					
					if(!strText.IsEmpty())
						bAllBlank = FALSE;
				}
			}
			
			if(nColCtrlCount > 1)
			{
				CString strTotal;
				strTotal.Format(_T("%d"), nTotal);
				
				CLinkEdit* pTotalEdit = (CLinkEdit*)pCtrlArrays[nColCtrlCount - 1].pLinkCtrl;
				
				if(pTotalEdit && !bAllBlank)//  if all are blank, not to sum
					pTotalEdit->SetWindowText(strTotal);
			}
		}
		
	}
	
	return TRUE;
}

int	CScrollPage::PageSaveData(CString strMRN, int nDiagSN, BOOL bIsDraft, DWORD dwScaleID, INPUT_FIELD_INFO* ppCtrlArrays[], int nColCtrlCount)
{
	if(strMRN.IsEmpty())
	{
		GYMsgBox(IDS_PAT_MRN_EMPTY, MB_OK|MB_ICONSTOP);
		return SaveBCE_Other;
	}

	BOOL bAllFull = TRUE;
	BOOL bAllBlank = TRUE;

	for(int i = 0; i < nColCtrlCount; i++)
	{
		LPVOID pCtrl = ppCtrlArrays[2][i].pLinkCtrl;
		if(!pCtrl)
			return SaveBCE_Other;

		if(ppCtrlArrays[2][i].dwCtrlType == IBT_ComboBox)
		{
			CLinkComboBox* pCombo = (CLinkComboBox*)ppCtrlArrays[2][i].pLinkCtrl;
			
			CString strText = pCombo->GetControlData();
			if(_ttoi(strText) > 0)
				bAllBlank = FALSE;
			else
				bAllFull = FALSE;
		}
		else if(ppCtrlArrays[2][i].dwCtrlType == IBT_EditBox)
		{
			CLinkEdit* pEdit = (CLinkEdit*)ppCtrlArrays[2][i].pLinkCtrl;
			
			CString strText = pEdit->GetControlData();
			if(strText.IsEmpty())
				bAllFull = FALSE;
			else
				bAllBlank = FALSE;
		}
		else
		{
			ASSERT(FALSE);
		}
	}

	if(!bAllFull && !bAllBlank)
	{
		CString strFormat = GetResString(IDS_PAT_INCOMPLETE);

		DWORD dwScaleStringId = GetStringIdFromScale(dwScaleID);
		CString strInfo;
		strInfo.Format(strFormat, GetResString(dwScaleStringId));

		GYMsgBox(strInfo, MB_OK|MB_ICONWARNING);
		return SaveBCE_Other;
	}
	
	if(bAllBlank)
		return SaveBCE_PageBlank;

	//  The body check record exists?
	CString strSQL;
	strSQL.Format(_T("SELECT BCID, COUNT(BCID) AS RecCnt FROM BodyCheckReg WHERE MedicalRecordNo='%s' AND DiagSN=%d AND ScaleID=%d"), strMRN, nDiagSN, dwScaleID);
	CGYDataSet bc(strSQL);

	CString strRecCnt;
	bc.GetFieldValue(_T("RecCnt"), strRecCnt);
	int nRecCnt = _ttoi(strRecCnt);
	if(nRecCnt > 1)
	{
		CString strFormat = GetResString(IDS_GBL_DATA_DUPLICATE);
		CString strError;
		strError.Format(strFormat, strSQL);
		GYMsgBox(strError, MB_OK|MB_ICONERROR);
		return SaveBCE_Database;
	}

	BOOL bExistRecord = FALSE;
	CString strBCID;
	if(nRecCnt == 1)
	{
		bExistRecord = TRUE;
		
		bc.GetFieldValue(_T("BCID"), strBCID);
		strSQL.Format(_T("UPDATE BodyCheckReg SET IsDraft=%d WHERE BCID=%s"), bIsDraft, strBCID);
		bc.ExecuteSQL(strSQL);
	}
	else
	{
		//  Reg the BodyCheck this time
		CTime curTime = CTime::GetCurrentTime();
		CString strCheckDate;
		strCheckDate.Format(_T("%4d-%02d-%02d"), curTime.GetYear(), curTime.GetMonth(), curTime.GetDay());
		
		//  Start transation
		bc.BeginTrans();
		strSQL.Format(_T("INSERT INTO BodyCheckReg (MedicalRecordNo, DiagSN, CheckDate, ScaleID, IsDraft) VALUES ('%s', %d, '%s', %d, %d)"), strMRN, nDiagSN, strCheckDate, dwScaleID, bIsDraft);
		BOOL bRet = bc.ExecuteSQL(strSQL);
		if(!bRet)
		{
			bc.Rollback();
			DataErrorMsgBox(__FILE__, __LINE__, strSQL, bc.GetLastErrorString());
			return SaveBCE_Database;
		}

		strSQL.Format(_T("SELECT BCID, COUNT(BCID) AS RecCnt FROM BodyCheckReg WHERE MedicalRecordNo='%s' AND DiagSN=%d AND CheckDate='%s' AND ScaleID=%d"), strMRN, nDiagSN, strCheckDate, dwScaleID);
		bc.OpenTable(strSQL);
		bc.GetFieldValue(_T("BCID"), strBCID);

		//  Commit transation
		bc.CommitTrans();	
	}

	BOOL bSQLRet = TRUE;
	CString strText;
	for(i = 0; bSQLRet && i < nColCtrlCount; i++)
	{
		if(ppCtrlArrays[2][i].dwCtrlType == IBT_ComboBox)
		{
			CLinkComboBox* pCombo = (CLinkComboBox*)ppCtrlArrays[2][i].pLinkCtrl;
			strText = pCombo->GetControlData();

			int nSel = _ttoi(strText);
			pCombo->GetLBText(nSel, strText);
		}
		else if(ppCtrlArrays[2][i].dwCtrlType == IBT_EditBox)
		{
			CLinkEdit* pEdit = (CLinkEdit*)ppCtrlArrays[2][i].pLinkCtrl;
			strText = pEdit->GetControlData();
		}
		else
		{
			ASSERT(FALSE);
		}
		
		if(bExistRecord)
		{
			strSQL.Format(_T("UPDATE BodyCheckResult SET FieldValue='%s' WHERE BCID=%s AND FieldID=%s"),
				strText, strBCID, ppCtrlArrays[2][i].szFieldName);
		}
		else
		{
			strSQL.Format(_T("INSERT INTO BodyCheckResult (BCID, FieldID, FieldValue) VALUES (%s, %s, '%s')"),
				strBCID, ppCtrlArrays[2][i].szFieldName, strText);
		}
		
		bSQLRet = bc.ExecuteSQL(strSQL);
		if(!bSQLRet)
			return SaveBCE_Database;
	}

	return SaveBCE_Succ;

}

BOOL CScrollPage::PageShowTableData(CString strMRN, int nDiagSN, DWORD dwScaleID, INPUT_FIELD_INFO* ppCtrlArrays[], int nColCtrlCount, CWnd* pDateLabelArray[], CWnd* pDiagSNArray[], int nStartCol)
{
	if(nDiagSN < 0 || nStartCol > 2 || nStartCol < 0)
		return FALSE;

	CString strSQL;
	if(nDiagSN == 0)
		strSQL.Format(_T("SELECT CheckDate, DiagSN, BCID, IsDraft FROM BodyCheckReg WHERE MedicalRecordNo='%s' AND DiagSN = 0 AND ScaleID=%d ORDER BY CheckDate DESC LIMIT 3"), strMRN, dwScaleID);
	else
		strSQL.Format(_T("SELECT CheckDate, DiagSN, BCID, IsDraft FROM BodyCheckReg WHERE MedicalRecordNo='%s' AND DiagSN > 0 AND DiagSN <= %d AND ScaleID=%d ORDER BY CheckDate DESC LIMIT %d"), strMRN, nDiagSN, dwScaleID, (nStartCol + 1));
	
	CGYDataSet tblBCReg(strSQL);
	if(tblBCReg.IsEOF())
	{
		for(int i = 0; i < nColCtrlCount; i++)
		{
			if(ppCtrlArrays[2][i].dwCtrlType == IBT_ComboBox)
			{
				CLinkComboBox* pCombo = (CLinkComboBox*)ppCtrlArrays[2][i].pLinkCtrl;
				if(pCombo)
				{
					pCombo->SetCurSel(0);
					pCombo->EnableWindow(FALSE);
				}
			}
			else if(ppCtrlArrays[2][i].dwCtrlType == IBT_EditBox)
			{
				CLinkEdit* pEdit = (CLinkEdit*)ppCtrlArrays[2][i].pLinkCtrl;
				if(pEdit)
				{
					pEdit->SetWindowText(_T(""));
					pEdit->SetReadOnly(FALSE);
				}
			}
			else
			{
				ASSERT(FALSE);
			}
		}

		if(nDiagSN == 0 && pDiagSNArray[2])
		{
			pDiagSNArray[2]->SetWindowText(GetResString(IDS_QRY_1ST_DIAG));
		}

		return TRUE;
	}
	
	CString astrCheckDate[3];
	CString astrBCID[3];
	CString strIsDraft;
	CString strDiagSN;

	BOOL bIndentCol = FALSE;
	for(int i = nStartCol; i >= 0 && !tblBCReg.IsEOF(); tblBCReg.MoveNext(), i--)
	{
		CString strChkDate;
		CString strBCid;

		tblBCReg.GetFieldValue(_T("CheckDate"), strChkDate);
		tblBCReg.GetFieldValue(_T("BCID"), strBCid);
		tblBCReg.GetFieldValue(_T("DiagSN"), strDiagSN);

		//  the specified Diagnose SN is exist? If not, start at next col
		if(i == 2)
		{
			if(nDiagSN > 0 && _ttoi(strDiagSN) != nDiagSN)
			{
				i--;
				if(i < 0)
					break;

				bIndentCol = TRUE;
			}
		}

		astrCheckDate[i] = strChkDate;
		astrBCID[i] = strBCid;
		
		if(pDateLabelArray[i])
		{
			astrCheckDate[i] = astrCheckDate[i].Left(10);
			pDateLabelArray[i]->SetWindowText(astrCheckDate[i]);
		}
		if(pDiagSNArray[i])
		{
			CString strDiag;
			if(nDiagSN == 0)
				strDiag = GetResString(IDS_QRY_1ST_DIAG);
			else
				strDiag.Format(_T("%s %s"), GetResString(IDS_TABTITLE_SUBSEDIAG), strDiagSN);

			pDiagSNArray[i]->SetWindowText(strDiag);
		}
		
		if(i == 2)
			tblBCReg.GetFieldValue(_T("IsDraft"), strIsDraft);
	}
	tblBCReg.Close();
	
	for(int j = (bIndentCol ? nStartCol - 1 : nStartCol); j >= 0 && !astrBCID[j].IsEmpty(); j--)
	{
		strSQL.Format(_T("SELECT FieldID, FieldValue FROM BodyCheckResult WHERE BCID=%s ORDER BY FieldID"), astrBCID[j]);
		
		CGYDataSet tblBCResult;
		tblBCResult.OpenTable(strSQL);
		
		BOOL bIsDraft = _ttoi(strIsDraft);
		
		CString strFieldID, strFieldValue;
		
		for(int i = 0; !tblBCResult.IsEOF(); tblBCResult.MoveNext(), i++)
		{
#ifdef _DEBUG
			tblBCResult.GetFieldValue(_T("FieldID"), strFieldID);
			ASSERT(strFieldID == ppCtrlArrays[2][i].szFieldName);
#endif
			tblBCResult.GetFieldValue(_T("FieldValue"), strFieldValue);

			if(ppCtrlArrays[j][i].dwCtrlType == IBT_ComboBox)
			{
				CLinkComboBox* pCombo = (CLinkComboBox*)ppCtrlArrays[j][i].pLinkCtrl;
				if(pCombo)
				{
					int nSel = 0;
					int nItemCount = pCombo->GetCount();
					for(int k = 1; k < nItemCount; k++)
					{
						CString strItemText;
						pCombo->GetLBText(k, strItemText);
						if(strItemText.CompareNoCase(strFieldValue) == 0)
						{
							nSel = k;
							break;
						}
					}

					pCombo->SetCurSel(nSel);

					if(ppCtrlArrays[j][i].bAlwaysReadOnly)
						pCombo->EnableWindow(FALSE);
					else
						pCombo->EnableWindow(bIsDraft);
				}
			}
			else if(ppCtrlArrays[j][i].dwCtrlType == IBT_EditBox)
			{
				CLinkEdit* pEdit = (CLinkEdit*)ppCtrlArrays[j][i].pLinkCtrl;
				if(pEdit)
				{
					pEdit->SetWindowText(strFieldValue);
					
					if(ppCtrlArrays[j][i].bAlwaysReadOnly)
						pEdit->SetReadOnly(TRUE);
					else
						pEdit->SetReadOnly(!bIsDraft);
				}
			}
			else
			{
				ASSERT(FALSE);
			}
		}
	}
	
	return _ttoi(strIsDraft);
}

BOOL CScrollPage::PageEnableInputControls(BOOL bEnable, INPUT_FIELD_INFO* ppCtrlArrays[], int nColCtrlCount)
{
	for(int i = 0; i < nColCtrlCount; i++)
	{
		if(ppCtrlArrays[2][i].dwCtrlType == IBT_ComboBox)
		{
			CLinkComboBox* pCombo = (CLinkComboBox*)ppCtrlArrays[2][i].pLinkCtrl;
			if(pCombo)
			{
				if(ppCtrlArrays[2][i].bAlwaysReadOnly)
					pCombo->EnableWindow(FALSE);
				else
					pCombo->EnableWindow(bEnable);
			}
		}
		else if(ppCtrlArrays[2][i].dwCtrlType == IBT_EditBox)
		{
			CLinkEdit* pEdit = (CLinkEdit*)ppCtrlArrays[2][i].pLinkCtrl;
			if(pEdit)
			{
				if(ppCtrlArrays[2][i].bAlwaysReadOnly)
					pEdit->SetReadOnly(TRUE);
				else
					pEdit->SetReadOnly(!bEnable);
			}
		}
		else
		{
			ASSERT(FALSE);
		}
	}
	
	return TRUE;
}

DWORD CScrollPage::GetStringIdFromScale(DWORD dwScaleID)
{
	DWORD dwStringId = 0;
	switch(dwScaleID)
	{
		case CBCMiniMentalPage::BODYCHECKSCALEID:
			dwStringId = IDS_BCTAB_MINI_MENTAL;
			break;

		case CBCTinettiBalPage::BODYCHECKSCALEID:
			dwStringId = IDS_BCTAB_TINETTI_BAL;
			break;

		case CBCBergScorePage::BODYCHECKSCALEID:
			dwStringId = IDS_BCTAB_BERG_SCORE;
			break;
			
		case CBCFuglMeyerUpPage::BODYCHECKSCALEID:
			dwStringId = IDS_BCTAB_FUGL_MEYER_UPPER;
			break;
			
		case CBCFuglMeyerLowPage::BODYCHECKSCALEID:
			dwStringId = IDS_BCTAB_FUGL_MEYER_LOWER;
			break;

		case CBCHoldenWalkPage::BODYCHECKSCALEID:
			dwStringId = IDS_BCTAB_HOLDEN_WALK;
			break;

		case CBCFuglMeyerBalPage::BODYCHECKSCALEID:
			dwStringId = IDS_BCTAB_FUGL_MEYER_LOWER_BAL;
			break;

		case CBCReviseAshworthPage::BODYCHECKSCALEID:
			dwStringId = IDS_BCTAB_REVISE_ASHWORTH;
			break;

		case CBCBrunnstromPage::BODYCHECKSCALEID:
			dwStringId = IDS_BCTAB_BRUNNSTROM;
			break;

		case CBCDoctorWritePage::BODYCHECKSCALEID:
			dwStringId = IDS_BCTAB_DOCTOR_WRITE;
			break;
		
		default:
			ASSERT(FALSE);
	}

	return dwStringId;
}

BOOL CScrollPage::PageShowColTitle(CWnd* pDateLabelArray[], CString astrDate[], CWnd* pDiagSNArray[], int anDiagSN[], int nDateCtrlCount)
{
	if(pDateLabelArray == NULL || pDiagSNArray == NULL || astrDate == NULL || anDiagSN == NULL || nDateCtrlCount <= 0 || nDateCtrlCount > 3)
		return FALSE;
	
	for(int i = 0; i < nDateCtrlCount; i++)
	{
		if(pDateLabelArray[i])
		{
			pDateLabelArray[i]->SetWindowText(astrDate[i]);
		}

		if(pDiagSNArray[i])
		{
			if(anDiagSN[i] >= 0)
			{
				CString strDiag;

				if(anDiagSN[i] == 0)
					strDiag = GetResString(IDS_QRY_1ST_DIAG);
				else
					strDiag.Format(_T("%s %d"), GetResString(IDS_TABTITLE_SUBSEDIAG), anDiagSN[i]);

				pDiagSNArray[i]->SetWindowText(strDiag);
			}
		}
	}

	return TRUE;
}

BOOL CScrollPage::PageIsAllInputBlank(INPUT_FIELD_INFO pCtrlArrays3[], int nColCtrlCount)
{
	BOOL bAllBlank = TRUE;
	for(int i = 0; i < nColCtrlCount; i++)
	{
		if(pCtrlArrays3[i].pLinkCtrl == NULL)
		{
			ASSERT(FALSE);
			return FALSE;
		}
		
		if(pCtrlArrays3[i].dwCtrlType == IBT_ComboBox)
		{
			CLinkComboBox* pCombo = (CLinkComboBox*)pCtrlArrays3[i].pLinkCtrl;
			CString strSel = pCombo->GetControlData();
			if(_ttoi(strSel) > 0)
			{
				bAllBlank = FALSE;
				break;
			}
		}
		else if(pCtrlArrays3[i].dwCtrlType == IBT_EditBox)
		{
			CLinkEdit* pEdit = (CLinkEdit*)pCtrlArrays3[i].pLinkCtrl;
			CString strText = pEdit->GetControlData();
			if(!strText.IsEmpty())
			{
				bAllBlank = FALSE;
				break;
			}
		}
	}
	
	return bAllBlank;
}
